<template>
    <!-- 列表 -->
    <ContentWrap>
        <el-table v-loading="loading" :data="list">
            <el-table-column align="center" key="id" label="编号" prop="id" />
            <el-table-column align="center" :show-overflow-tooltip="true" label="身高(cm)" prop="heightRecord" />
            <el-table-column align="center" :show-overflow-tooltip="true" label="体重(kg)" prop="weightRecord" />
            <el-table-column align="center" :formatter="dateFormatter" label="记录时间" prop="recordDate" />
        </el-table>
        <!-- 分页 -->
        <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
            @pagination="getList" />
    </ContentWrap>
</template>

<script lang="ts" setup>
import { dateFormatter } from '@/utils/formatTime'
import * as ChildApi from '@/api/member/child'

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
    pageNo: 1,
    pageSize: 10,
    childId: undefined
})

/** 查询列表 */
const getList = async () => {
    loading.value = true
    try {
        const data = await ChildApi.getRecordList(queryParams)
        list.value = data.list
        total.value = data.total
    } finally {
        loading.value = false
    }
}

const props = defineProps({
    childId: {
        type: Number,
        required: true
    }
})

watch(
    () => props.childId,
    (newVal) => {
        if (newVal) {
            queryParams.childId = newVal;
            getList();
        }
    },
    { immediate: true }
)
</script>
